package nongchang.kuaijiecaifu.com.ncapp_android.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import ezy.lite.util.ContextUtil;
import ezy.lite.util.DateTime;
import ezy.widget.view.AutofitImageView;
import nongchang.kuaijiecaifu.com.ncapp_android.R;
import nongchang.kuaijiecaifu.com.ncapp_android.common.adapter.ItemAdapter;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.main.Evaluate;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.AddEvaluateActivity;

/**
 * Created by Administrator on 2016/5/12 0012.
 */
public class EvaluateAdapter extends ItemAdapter<Evaluate, EvaluateAdapter.EvaluateHolder> {
    private Context context;

    public EvaluateAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public EvaluateHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new EvaluateHolder(inflate(R.layout.item_evaluate, parent));
    }

    @Override
    public void onBindViewHolder(EvaluateHolder holder, int position) {
        Evaluate item = getItem(position);
        Glide.with(context).load(item.image).into(holder.imgShop);
        holder.txtTitle.setText(item.title);
        holder.txtContent.setText(item.content);
        holder.txtTime.setText(DateTime.toDate(item.time*1000));
    }

    static class EvaluateHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @BindView(R.id.img_shop)
        AutofitImageView imgShop;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.ratingbar)
        RatingBar ratingbar;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.txt_time)
        TextView txtTime;

        public EvaluateHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            ContextUtil.startActivity(v.getContext(), AddEvaluateActivity.class);
        }
    }

}
